import guicomponents.*;


GPanel pnlControls;
GCombo cboColor, cboLabel, cboSize, cboX, cboY;
GOption optHand, optXhair, optMove, optText,optWait;
PFont plotFont;
int selectedX = 0;
 int selectedY = 0;
int vitInterval = 100;
int podInterval = 100;
int corInterval = 100;
int poleInterval = 100;
int titInterval = 5;
PImage mapImage;
Table locationTable;
int rowCount;
float plotX1, plotY1; 
float plotX2, plotY2; 

FloatTable dataTable; 

float dataMin = MAX_FLOAT;
float dataMax = MIN_FLOAT;
float dataMin2 = MAX_FLOAT;
float dataMax2 = MIN_FLOAT;
float dataMin3 = MAX_FLOAT;
float dataMax3 = MIN_FLOAT;
float dataMin4 = MAX_FLOAT;
float dataMax4 = MIN_FLOAT;
float dataMin5 = MAX_FLOAT;
float dataMax5 = MIN_FLOAT;
float percent = 0;

void setup() {
  
  size(1300, 574);
  createCombos();
  createCombos2();
   mapImage = loadImage("mapa3.png");
  locationTable = new Table("locations.tsv");
  rowCount = locationTable.getRowCount();
  // Read the data table
 dataTable = new FloatTable("data.txt");
   // acho os valores maximos e minimos e uso eles em todos os casos
  plotX1 = 100; 
  plotX2 = 500; 
  plotY1 = 100; 
  plotY2 = 500; 
 

smooth();
  noStroke(); 
 
}


void draw() {
  
 if (key =='m'){
    for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 0);
    if (value > dataMax) {
      dataMax = value;
    }
    if (value < dataMin) {
      dataMin = value;
    }
  }
  
    for (int row = 0; row < rowCount; row++) {
   float value = dataTable.getFloat(row, 1);
    if (value > dataMax2) {
      dataMax2 = value;
    }
    if (value < dataMin2) {
      dataMin2 = value;
    }
  }

    for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 2);
    if (value > dataMax3) {
      dataMax3 = value;
    }
    if (value <
    dataMin3) {
      dataMin3 = value;
    }
  }
    
 
  background(255);
  image(mapImage, 0, 0);
  handleComboEvents2(cboSize, cboColor);
  handleComboEvents(cboLabel);
 
  smooth();
  noStroke(); 
  
 }  
  if (key == 'n'){
    
         for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 0);
    if (value > dataMax) {
      dataMax = value;
    }
     dataMin = 0;
  }
  
    for (int row = 0; row < rowCount; row++) {
   float value = dataTable.getFloat(row, 1);
    if (value > dataMax2) {
      dataMax2 = value;
    }
     dataMin2 = 0;
  }
  
   for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 2);
    if (value > dataMax3) {
      dataMax3 = value;
    }
     dataMin3 = 0;
  }
      for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 3);
    if (value > dataMax4) {
      dataMax4 = value;
    }
  dataMin4 = 0;
  }
         for (int row = 0; row < rowCount; row++) {
    float value = dataTable.getFloat(row, 4);
    if (value > dataMax5) {
      dataMax5 = value;
    }
  dataMin5 = 0;
  }
 dataMax5 = ceil(dataMax5/ titInterval) * titInterval;
 dataMax4 = ceil(dataMax4/ poleInterval) * poleInterval;
 dataMax3 = ceil(dataMax3/ corInterval) * corInterval;
 dataMax2 = ceil(dataMax2/ podInterval) * podInterval;
 dataMax = ceil(dataMax/ vitInterval) * vitInterval;


 background(224);   
 fill(255); 
 rectMode(CORNERS); 
 
 rect(plotX1, plotY1, plotX2, plotY2);   
 handleComboEvents3(cboX, cboY);
 drawTitle();
 smooth();
  noStroke(); 
    
    
  }
}
  
  void drawTitle() {
  //fill(0);
  
  textAlign(LEFT);
  String title = "Informações da História dos Países na Fórmula 1";
 text(title, width/2 - 420, height - 480); 
}
  
 
 int vitIntervalMinor = 50; 

//Número de vitórias
void drawVitY() {
 fill(0);
  textSize(10);
  textAlign(RIGHT);
  
   stroke(128);
  strokeWeight(1);

  for (float v = dataMin; v <= dataMax; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {    
      float y = map(v, dataMin, dataMax, plotY2, plotY1);  
      if (v % podInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin) {
          textOffset = 0; 
        } else if (v == dataMax) {
          textOffset = textAscent();        
        }
        
         text(floor(v), plotX1 - 10, y + textOffset);
         line(plotX1 - 4, y, plotX1, y);
         } else {
        line(plotX1 - 2, y, plotX1, y);     // Draw minor tick
      }
        
        
      } 
    }
  
}


 

void drawVitX() {
 fill(0);
  textSize(10);
  textAlign(CENTER);
  
   stroke(224);
  strokeWeight(1);

  for (float v = dataMin; v <= dataMax; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float x = map(v, dataMin, dataMax, plotX1, plotX2);  
      if (v % podInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin) {
          textOffset = 0;                   
        } else if (v == dataMax) {
          textOffset = textAscent();       
        }
        text(floor(v), x,  plotY2 + textAscent() + 10);
        line(x, plotY1, x, plotY2);
        
      } 
    }
  }
}

//Número de poles
void drawPoleY() {
 fill(0);
  textSize(10);
  textAlign(RIGHT);
  
   stroke(128);
  strokeWeight(1);

  for (float v = dataMin4; v <= dataMax4; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {    
      float y = map(v, dataMin4, dataMax4, plotY2, plotY1);  
      if (v % podInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin4) {
          textOffset = 0; 
        } else if (v == dataMax4) {
          textOffset = textAscent();        
        }
        
         text(floor(v), plotX1 - 10, y + textOffset);
         line(plotX1 - 4, y, plotX1, y);
         } else {
        line(plotX1 - 2, y, plotX1, y);     // Draw minor tick
      }
        
        
      } 
    }
  
}


 

void drawPoleX() {
 fill(0);
  textSize(10);
  textAlign(CENTER);
  
   stroke(224);
  strokeWeight(1);

  for (float v = dataMin4; v <= dataMax4; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float x = map(v, dataMin4, dataMax4, plotX1, plotX2);  
      if (v % podInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin4) {
          textOffset = 0;                   
        } else if (v == dataMax4) {
          textOffset = textAscent();       
        }
        text(floor(v), x,  plotY2 + textAscent() + 10);
        line(x, plotY1, x, plotY2);
        
      } 
    }
  }
}

//Número de titulos
void drawChampsY() {
 fill(0);
  textSize(10);
  textAlign(RIGHT);
  
   stroke(128);
  strokeWeight(1);

  for (float v = dataMin5; v <= dataMax5; v += 2.5) {
    if (v % 2.5 == 0) {    
      float y = map(v, dataMin5, dataMax5, plotY2, plotY1);  
      if (v % titInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin5) {
          textOffset = 0; 
        } else if (v == dataMax5) {
          textOffset = textAscent();        
        }
        
         text(floor(v), plotX1 - 10, y + textOffset);
         line(plotX1 - 4, y, plotX1, y);
         } else {
        line(plotX1 - 2, y, plotX1, y);     // Draw minor tick
      }
        
        
      } 
    }
  
}


 

void drawChampsX() {
 fill(0);
  textSize(10);
  textAlign(CENTER);
  
   stroke(224);
  strokeWeight(1);

  for (float v = dataMin5; v <= dataMax5; v += 2.5) {
    if (v % 2.5 == 0) {     
      float x = map(v, dataMin5, dataMax5, plotX1, plotX2);  
      if (v % titInterval == 0) {        
        float textOffset = textAscent()/2;  
        if (v == dataMin5) {
          textOffset = 0;                   
        } else if (v == dataMax5) {
          textOffset = textAscent();       
        }
        text(floor(v), x,  plotY2 + textAscent() + 10);
        line(x, plotY1, x, plotY2);
        
      } 
    }
  }
}

//Número de podiuns
void drawPodY() {
 fill(0);
  textSize(10);
  textAlign(RIGHT);
  
   stroke(128);
  strokeWeight(1);

  for (float v = dataMin2; v <= dataMax2; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float y = map(v, dataMin2, dataMax2, plotY2, plotY1);  
      if (v % podInterval == 0) {       
        float textOffset = textAscent()/2;  
        if (v == dataMin2) {
          textOffset = 0;                  
        } else if (v == dataMax2) {
          textOffset = textAscent();       
        }
        
         text(floor(v), plotX1 - 10, y + textOffset);
        line(plotX1 - 4, y, plotX1, y);
         } else {
        line(plotX1 - 2, y, plotX1, y);     // Draw minor tick
      }
        
      
    }
  }
}


 

void drawPodX() {
 fill(0);
  textSize(10);
  textAlign(CENTER);
  
   stroke(224);
  strokeWeight(1);

  for (float v = dataMin2; v <= dataMax2; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float x = map(v, dataMin2, dataMax2, plotX1, plotX2);  
      if (v % podInterval == 0) {       
        float textOffset = textAscent()/2;  
        if (v == dataMin2) {
          textOffset = 0;                   
        } else if (v == dataMax2) {
          textOffset = textAscent();      
        }
        text(floor(v), x,  plotY2 + textAscent() + 10);
        line(x, plotY1, x, plotY2);
        
      } 
    }
  }
}




//Número de corridas
void drawCorY() {
 fill(0);
  textSize(10);
  textAlign(RIGHT);
  
   stroke(128);
  strokeWeight(1);

  for (float v = dataMin3; v <= dataMax3; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float y = map(v, dataMin3, dataMax3, plotY2, plotY1);  
      if (v % podInterval == 0) {       
        float textOffset = textAscent()/2;  
        if (v == dataMin3) {
          textOffset = 0;                  
        } else if (v == dataMax3) {
          textOffset = textAscent();        
        }
        
         text(floor(v), plotX1 - 10, y + textOffset);
        line(plotX1 - 4, y, plotX1, y);
         } else {
        line(plotX1 - 2, y, plotX1, y);     // Draw minor tick
      }
        
      
    }
  }
}


 

void drawCorX() {
 fill(0);
  textSize(10);
  textAlign(CENTER);
  
   stroke(224);
  strokeWeight(1);

  for (float v = dataMin3; v <= dataMax3; v += vitIntervalMinor) {
    if (v % vitIntervalMinor == 0) {     
      float x = map(v, dataMin3, dataMax3, plotX1, plotX2);  
      if (v % podInterval == 0) {       
        float textOffset = textAscent()/2;  
        if (v == dataMin3) {
          textOffset = 0;                   
        } else if (v == dataMax3) {
          textOffset = textAscent();        
        }
        text(floor(v), x,  plotY2 + textAscent() + 10);
        line(x, plotY1, x, plotY2);
        
      } 
    }
  }
}


 




//funcao que desenhae pinta as elipses e coloca a label de acordo
//com as opcoes marcadas nos menus
//As opcoes possiveis sao: numero de corridas, numero de vitórias
//e numero de podiuns que cada pais ja teve na historia da formula 1

void drawData(float x, float y, String abbrev, int dimension, GCombo combo) {
smooth();
fill(0);

text("Por cor", width - 460, height - 80); 
text("Por label", width - 620, height - 80);
text("Por tamanho", width - 780, height - 80);

  int value = dataTable.getInt(abbrev, 0); 
  int value2 = dataTable.getInt(abbrev, 1); 
  int value3 = dataTable.getInt(abbrev, 2);
  float radius = 0;


if ( dimension == 1 && combo == cboSize) {
    percent = norm(value, dataMin, dataMax);
  color between = lerpColor(#FFFFFF, #4422CC, percent);  
  fill(between);
 
 
 
  radius = map(value, 0, dataMax, 2, 14);
  // Draw an ellipse for this item
 ellipseMode(RADIUS);
  
  ellipse(x, y, radius, radius);
}
if ( dimension == 2 && combo == cboSize) {
   percent = norm(value2, dataMin2, dataMax2);
    color between = lerpColor(#FFFFFF, #4422CC, percent);  
  fill(between);
 
  
  radius = map(value, 0, dataMax, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 3 && combo == cboSize) {
   percent = norm(value3, dataMin3, dataMax3);
    color between = lerpColor(#FFFFFF, #4422CC, percent); 
  fill(between);
 
  
  radius = map(value, 0, dataMax, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 4 && combo == cboSize) {
   percent = norm(value, dataMin, dataMax);
    color between = lerpColor(#FFFFFF, #4422CC, percent);  
    fill(between);
 
 
  radius = map(value2, 0, dataMax2, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 5 && combo == cboSize) {
   percent = norm(value2, dataMin2, dataMax2);
    color between = lerpColor(#FFFFFF, #4422CC, percent);  
    fill(between);
 
 
  radius = map(value2, 0, dataMax2, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 6 && combo == cboSize) {
   percent = norm(value3, dataMin3, dataMax3);
    color between = lerpColor(#FFFFFF, #4422CC, percent); 
    fill(between);
 
 
  radius = map(value2, 0, dataMax2, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}

if ( dimension == 7 && combo == cboSize) {
   percent = norm(value, dataMin, dataMax);
    color between = lerpColor(#FFFFFF, #4422CC, percent);
    fill(between);
 
 
  radius = map(value3, 0, dataMax3, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 8 && combo == cboSize) {
   percent = norm(value2, dataMin2, dataMax2);
    color between = lerpColor(#FFFFFF, #4422CC, percent);
    fill(between);
 
 
  radius = map(value3, 0, dataMax3, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
if ( dimension == 9 && combo == cboSize) {
   percent = norm(value3, dataMin3, dataMax3);
    color between = lerpColor(#FFFFFF, #4422CC, percent);  
    fill(between);
 
 
  radius = map(value3, 0, dataMax3, 2, 14);
  // Draw an ellipse for this itemi
 ellipseMode(RADIUS);

  ellipse(x, y, radius, radius);
}
  //setando para labels
  if (dist(x, y, mouseX, mouseY) < radius+5 && dimension == 1 && 
 combo == cboLabel) {
    fill(0);
   
    
    // mostra a abrev do país e o número de vitórias 
   text(abbrev+ "," +value, x, y-radius-4);
  }
    if (dist(x, y, mouseX, mouseY) < radius+5 && dimension == 2
    && combo == cboLabel) {
 fill(0);
  
    // mostra a abrev do país e o número de podiuns
   text(abbrev+ ","+ value2, x, y-radius-4);
  }
      if (dist(x, y, mouseX, mouseY) < radius+5 && dimension == 3
    && combo == cboLabel) {
 fill(0);
  
    // mostra a abrev do país e o número de corridas disputadas por todos os pilotos daquele país
   text(abbrev+ ","+ value3, x, y-radius-4);
  }
}
//funcao que cria os menus
public void createCombos() {
  String[] colors = new String[] {
  "n° vitorias", "n° podiums" , "n° corridas" };
  cboColor = new GCombo(this, colors, 3, width - 460, height - 70, 160);
  cboColor.setSelected(0);
  String[] labels = new String[] { 
    "n° vitorias", "n° podiums" , "n° corridas"};
  cboLabel = new GCombo(this, labels, 3,width -  620, height - 70, 160);
  cboLabel.setSelected(0);
    String[] sizes = new String[] { 
    "n° vitorias", "n° podiums", "n° corridas"};
  cboSize = new GCombo(this, sizes, 3, width - 780, height - 70, 160);
    cboSize.setSelected(0);

}





//funcao para comandar as acoes relacionadas a label

public void handleComboEvents(GCombo combo){
  if(cboLabel == combo && cboLabel.selectedIndex() == 0 ){
   for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 1, cboLabel);
  }
   
  }
 
 if(cboLabel == combo && cboLabel.selectedIndex() == 1 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 2, cboLabel);
  }
   
  }
   if(cboLabel == combo && cboLabel.selectedIndex() == 2 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 3, cboLabel);
  }
   
  }
}

//funcao para comandar as acoes relacionadas a cor e tamanho
 public void handleComboEvents2(GCombo combo, GCombo combo2){

 if(cboSize == combo && cboSize.selectedIndex() == 0 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 0 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 1, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 0 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 1 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 2, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 0 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 2 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 3, cboSize);
  }
 }
 }	
  if(cboSize == combo && cboSize.selectedIndex() == 1 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 0 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 4, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 1 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 1 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 5, cboSize);
  }
 }
 }
 
  if(cboSize == combo && cboSize.selectedIndex() == 1 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 2 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 6, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 2 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 0 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 7, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 2 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 1 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 8, cboSize);
  }
 }
 }
  if(cboSize == combo && cboSize.selectedIndex() == 2 ){
   if(cboColor == combo2 && cboColor.selectedIndex() == 2 ){
    for (int row = 0; row < rowCount; row++) {
    String abbrev = dataTable.getRowName(row);
    float x = locationTable.getFloat(abbrev, 1);
    float y = locationTable.getFloat(abbrev, 2);
    drawData(x, y, abbrev, 9, cboSize);
  }
 }
 }
   
  
   
}

public void createCombos2() {
  String[] X = new String[] {
  "n° vitorias", "n° podiums" , "n° corridas", "n° poles", "n° titulos" };
  cboX = new GCombo(this, X, 5, width - 1200, height - 500, 100);
  cboX.setSelected(0);
  String[] Y = new String[] { 
    "n° vitorias", "n° podiums" , "n° corridas", "n° poles", "n° titulos"};
  cboY = new GCombo(this, Y, 5,width -  1300, height - 500, 100);
  cboY.setSelected(0);
}

public void handleComboEvents3(GCombo combo, GCombo combo2){
 
  
  if(cboX == combo && cboX.selectedIndex() == 0 ){
    drawVitX();
    selectedX = cboX.selectedIndex();
  }
  
   if(cboX == combo && cboX.selectedIndex() == 1 ){
    drawPodX();
    selectedX = cboX.selectedIndex();
  }
   if(cboX == combo && cboX.selectedIndex() == 2 ){
    drawCorX();
    selectedX = cboX.selectedIndex();
  }
     if(cboX == combo && cboX.selectedIndex() == 3 ){
    drawPoleX();
    selectedX = cboX.selectedIndex();
  }
       if(cboX == combo && cboX.selectedIndex() == 4 ){
    drawChampsX();
    selectedX = cboX.selectedIndex();
  }
  
   if(cboY == combo2 && cboY.selectedIndex() == 0 ){
    drawVitY();
    selectedY = cboY.selectedIndex();
  }
  
   if(cboY == combo2 && cboY.selectedIndex() == 1 ){
    drawPodY();
    selectedY = cboY.selectedIndex();
  }
   if(cboY == combo2 && cboY.selectedIndex() == 2 ){
    drawCorY();
    selectedY = cboY.selectedIndex();
  }
     if(cboY == combo2 && cboY.selectedIndex() == 3 ){
    drawPoleY();
    selectedY = cboY.selectedIndex();
  }
 
     if(cboY == combo2 && cboY.selectedIndex() == 4 ){
    drawChampsY();
    selectedY = cboY.selectedIndex();
  }
  
  strokeWeight(6); 
  stroke(#5679C1); 
  drawDataPoints(selectedX,selectedY); 
  strokeWeight(0);
  noStroke();
   
  }
  
  // Draw the data as a series of points 
void drawDataPoints(int k,int j) { 
  text("Coodenada X", width - 1130, height - 510); 
  text("Coordenada Y", width - 1230, height - 510);
  float x=0;
  float y=0;
  int rowCount = dataTable.getRowCount(); 
  for (int row = 0; row < rowCount; row++) { 
    
      float value = dataTable.getFloat(row, k);
      float value2 = dataTable.getFloat(row, j);
      String country = dataTable.getRowName(row);
      
       if (k==0){
      x = map(value, dataMin, dataMax, plotY1, plotY2); 
  }
      else if (k==1){
        x = map(value, dataMin2, dataMax2, plotY1, plotY2); 
  }
        else if (k==2){
        x= map(value, dataMin3, dataMax3, plotY1, plotY2); 
  }
          else if (k==3){
        x= map(value, dataMin4, dataMax4, plotY1, plotY2); 
  }
          else if (k==4){
        x= map(value, dataMin5, dataMax5, plotY1, plotY2); 
  }
        if (j==0){
     y = map(value2, dataMin, dataMax, plotY2, plotY1);
  }
      else if (j==1){
        y = map(value2, dataMin2, dataMax2, plotY2, plotY1);
  }
        else if (j==2){
      y = map(value2, dataMin3, dataMax3, plotY2, plotY1);
  }
          else if (j==3){
      y = map(value2, dataMin4, dataMax4, plotY2, plotY1);
  }          else if (j==4){
      y = map(value2, dataMin5, dataMax5, plotY2, plotY1);
  }
  
  
      point(x, y); 
      
      if (dist(mouseX, mouseY, x, y) < 5) {
        strokeWeight(6);
        
        fill(0);
        
        textAlign(CENTER);
        text(round(value2)+","+round(value)+"("+country+")"  , x, y-10);
        textAlign(LEFT);
      }
    
  } 
} 

 




